<?php
  require_once 'DB.php';
  include_once("./libraries/db.inc.php");
  include_once("./libraries/authentication.inc.php");
  include_once("./queries/machine.inc.php");
  include_once("./libraries/util.inc.php");
  include_once("./libraries/displayUtils.inc.php");

  session_start();
  sessionAuthenticate("login.php");

  setUpDisplay("Machine Report");

  $connection=DB::connect($dsn, $options);
  if (DB::isError($connection)) {
    trigger_error($connection->getMessage(), E_USER_ERROR);
  }

  echo "<font size=5><center><b>Machine Report</b></center></font><br />\n";
  printLink("./index.php", "Take me back to the main screen!");
  if ($_SESSION["administrator"] === true) {
    echo "<br /><p>\n";
    printLink("./adminIndex.php", "Take me back to the Admin screen!");
  }

  //we're going to do machines by arch&opsys, state and activity
  //first arch&opsys
  $groupBy=array();
  $groupBy[0]="arch";
  $groupBy[1]="opsys";
  $aggs=array();
  $aggs[0]=array();
  $aggs[0]["func"]="count";
  $aggs[0]["field"]="*";
  $rs = machineclassAd_agg_query($groupBy, $aggs, $connection);
  
  $rs->setLinkParams(1, array("opsys"), array(1), "machineList.php");
  $rs->setLinkParams(0, array("arch"), array(0), "machineList.php");
  //$rs->simpleSetLinkParams(1, "opsys");
  //$rs->simpleSetLinkParams(0, "arch");
  //$rs->linkFile = "machineList.php";
  prettyDisplayAggQuery($rs, 2, array(0,1), "Machines by arch & opsys", "arch");
  
  $groupBy=array();
  $groupBy[0]="state";
  $rs = machineclassAd_agg_query($groupBy, $aggs, $connection);
  $rs->setLinkParams(0, array("state"), array(0), "machineList.php");
  //$rs->simpleSetLinkParams(0, "state");
  //$rs->linkFile = "machineList.php";
  prettyDisplayAggQuery($rs, 1, 0, "Machines by state", "state");  

  $groupBy=array();
  $groupBy[0]="activity";
  $rs=machineclassAd_agg_query($groupBy, $aggs, $connection);
  $rs->setLinkParams(0, array("activity"), array(0), "machineList.php");
  //$rs->simpleSetLinkParams(0, "activity");
  //$rs->linkFile = "machineList.php";
  prettyDisplayAggQuery($rs, 1, 0, "Machines by activity", "activity");

  cdbFinishPage();
  $connection->disconnect();

?>
